-
-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
让热重载时不刷新list #43 #44
Closed
Closed
让热重载时不刷新list #43 #44
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
我的想法是 在 继承 |
热重载更新ui不是很正常的事情吗? |
UI没有更新 是数据要重新加载 热重装需要重新请求接口加载数据 等请求返回 正常吗? |
你先了解下热重载做什么些啥,然后哪些情况下热重载无效 |
我也遇到了. loadData正常请求完毕, 返回了true, 但是UI界面没有更新, 点击热重载后才正常展示UI |
请使用最新版本 |
问题解决了,感觉是我的用法有问题,我把refresh方法注释掉恢复正常 ///照片墙加载更多
class UserPictureLoadmoreObject extends LoadingMoreBase<UserPictureModel> {
final String username;
UserPictureLoadmoreObject(this.username);
int pageindex = 1;
bool hasmore = true;
// @override
// Future<bool> refresh([bool notifyStateChanged = false]) async {
// pageindex = 1;
// hasmore = true;
// await loadData();
// return super.refresh(notifyStateChanged);
// }
@override
Future<bool> loadData([bool isloadMoreAction = false]) async {
final r = await (UsersPicturesApi()
..username = username
..page = pageindex)
.request(showDefaultLoading: false);
if (r.success) {
final lists = (r!.data as List<dynamic>).asList;
if (pageindex == 1) {
clear();
add(UserPictureModel.addButton());
}
final models = List<UserPictureModel>.from(lists.map((e) => UserPictureModel.fromMap(e))).toList();
addAll(models);
hasmore = lists.isNotEmpty;
pageindex++;
mylog('加载照片墙列表正常结束:$length ${r.data}');
return true;
} else {
mylog('加载照片墙出现问题');
return false;
}
}
@override
bool get hasMore => hasmore;
}
///照片墙列表
class UserPictureListWidget extends StatelessWidget {
final UserPictureLoadmoreObject repo;
const UserPictureListWidget({Key? key, required this.repo}) : super(key: key);
@override
Widget build(BuildContext context) {
return LoadingMoreList(ListConfig<UserPictureModel>(
itemBuilder: (c, item, index) {
if (item.isAddButtonWidget) {
return AddButton(repo);
}
return ExtendedImage.network(
'${item.url}=detail',
width: double.infinity,
height: double.infinity,
shape: BoxShape.rectangle,
borderRadius: 8.borderRadius,
fit: BoxFit.cover,
loadStateChanged: (s) => kImageLoadStateWidget(s, double.infinity, width: double.infinity, height: double.infinity),
).aspectRatio(112 / 150).bg(Colors.grey.shade100).clipRadius(8);
},
sourceList: repo,
extendedListDelegate: const SliverWaterfallFlowDelegateWithFixedCrossAxisCount(crossAxisCount: 3, mainAxisSpacing: 12, crossAxisSpacing: 12),
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
indicatorBuilder: (c, s) => kBuildIndicator(c, s, resp: repo)));
}
}
class AddButton extends ConsumerWidget {
final UserPictureLoadmoreObject repo;
const AddButton(this.repo, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
return AspectRatio(
aspectRatio: 112 / 150,
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(color: const Color(0xffF2F2F4), borderRadius: 8.borderRadius),
child: const Icon(
Icons.add,
size: 30,
),
),
).click(() async {
try {
UrlResult? result;
final success = await UploadImageUtil.uploadImage(context, UploadType.photoWall, PictureWallUploadApi(), urlResult: (v) {
result = v;
});
if (success == true) {
toast('添加成功');
repo.refresh();
}
} on ApiException catch (e) {
context.showSimpleDialog(e.msg);
}
});
}
}
class UserPictureModel {
final int id;
final String url;
bool get isAddButtonWidget {
return id == -1;
}
UserPictureModel({
required this.id,
required this.url,
});
UserPictureModel copyWith({
int? id,
String? url,
}) {
return UserPictureModel(
id: id ?? this.id,
url: url ?? this.url,
);
}
Map<String, dynamic> toMap() {
return <String, dynamic>{
'id': id,
'url': url,
};
}
factory UserPictureModel.addButton() {
return UserPictureModel(id: -1, url: "");
}
factory UserPictureModel.fromMap(Map<String, dynamic> map) {
return UserPictureModel(
id: map['id'] as int,
url: map['url'] as String,
);
}
String toJson() => json.encode(toMap());
factory UserPictureModel.fromJson(String source) => UserPictureModel.fromMap(json.decode(source) as Map<String, dynamic>);
@override
String toString() => 'UserPictureModel(id: $id, url: $url)';
@override
bool operator ==(covariant UserPictureModel other) {
if (identical(this, other)) return true;
return other.id == id && other.url == url;
}
@override
int get hashCode => id.hashCode ^ url.hashCode;
}
|
确实。super 里面已经做了 |
ghost
closed this by deleting the head repository
Jul 24, 2024
This pull request was closed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.